package com.bigShen.jdbc.basic.dao;

import com.bigShen.jdbc.basic.entity.UserInfo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author : lei.shen
 * @date : 2018/11/19
 */
public class UserDao {

    public List<UserInfo> getUserList(String userName) {

        List<UserInfo> infos = new ArrayList<UserInfo>();
        try {
            Connection con = BaseDao.getConnection();
            PreparedStatement statement = con.prepareStatement("SELECT * FROM TTRD_AUTH_USER WHERE USER_NAME = ?");
            statement.setString(1, userName);
            ResultSet rs = statement.executeQuery();

            while (rs.next()) {
                UserInfo userInfo = new UserInfo();
                userInfo.setUserNmae(rs.getString("USER_NAME"));
                userInfo.setChineseSpell(rs.getString("FULL_CHINESE_SPELL"));
                infos.add(userInfo);
            }
            BaseDao.closeAll(con, statement, rs);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return infos;
    }

}
